package com.hundsun.cprs.yyt.service.match.domain;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

public class DefaultTradeMatch extends TradeMatch {
    
    private AtomicInteger transactionCountSeq = new AtomicInteger(0);

	public DefaultTradeMatch() {
		super();
	}

	public DefaultTradeMatch(String stockCode) {
		super(stockCode);
	}

	public long getFundAmount() {
		long total = 0;
		for (TradeMatchDetail entrustMatch : this.getMatchDetails()) {
			total += entrustMatch.getMatchFundAmount();
		}
		return total / 2;//买卖都算了,所以会double一下,除2就对了
	}

	/**
	 * 连续竞价没有成交价格?
	 */
	public long getMatchPrice() {
		return 0;
	}

	public long getLastPrice() {
		List<TradeMatchDetail> details = this.getMatchDetails();
		if(details == null || details.isEmpty()){//不应该出现
			return 0;
		}
		TradeMatchDetail last = details.get(details.size()-1);
		return last.getMatchPrice();
	}

	public long getMaxPrice() {
		long max = 0;
		for(TradeMatchDetail entrustMatch : this.getMatchDetails()){
			long price = entrustMatch.getMatchPrice();
			if(price > max){
				max = price;
			}
		}
		return max;
	}

	public long getMinPrice() {
		long min = Long.MAX_VALUE;
		for(TradeMatchDetail entrustMatch : this.getMatchDetails()){
			long price = entrustMatch.getMatchPrice();
			if(price < min){
				min = price;
			}
		}
		return min;
	}

    public int getTransactionCountSeq() {
        return transactionCountSeq.incrementAndGet();
    }
}
